home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / GETC.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  65 lines

  1. /* 1.3  01-08-86                         (getc.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1986        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "stdio.h"
  11.  
  12. /************************************************************************/
  13.     METACHAR
  14. getc(fp)        /* Get and return next character from FILE fp.
  15.                Return EOF if unable to do so.        */
  16. /*----------------------------------------------------------------------*/
  17. FAST FILE *fp;
  18. {
  19.     FAST int siz, c;
  20.  
  21.     if (fp->_bptr >= fp->_bend)
  22.     {    if (fp->_flags & (_EOF | _IOERR)) /* if past end of file */
  23.             return EOF;
  24.  
  25.         fp->_flags &= ~_DIRTY;        /* clean the flush flag    */
  26.         if (fp->_buff IS NULL)        /* attach a buffer,    */
  27.             getbuf(fp);        /*   if not yet done.    */
  28.         if ((siz = read(fp->_unit, fp->_buff, fp->_buflen)) <= 0)
  29.         {    fp->_flags |= (siz IS 0) ? _EOF : _IOERR;
  30.             return EOF;
  31.         }
  32.  
  33.         fp->_bend = (fp->_bptr = fp->_buff) + siz;
  34.     }
  35.     _rowcol(c = *fp->_bptr++ & 0xff, fp);
  36.     return c;
  37.  
  38.     redirbuf();    /* a dummy call to be sure redirbuf is linked in
  39.                when a getc is made and input is redirected    */
  40. }
  41.  
  42. /*\p*********************************************************************/
  43.     METACHAR
  44. getca(fp)        /* Get and return next ASCII character from FILE
  45.                fp.  Return EOF if unable to do so. Suppress
  46.                '\r', file is assumed text.            */
  47. /*----------------------------------------------------------------------*/
  48. FAST FILE *fp;
  49. {
  50.     FAST int c;
  51.  
  52.     c = getc(fp);
  53. #ifdef SYS_EOF
  54.     if (c IS SYS_EOF)
  55.     {    --fp->_bptr;
  56.         return EOF;
  57.     }
  58. #endif
  59. #ifdef CRINSUP
  60.     if (c IS '\r' OR c IS NULL)
  61.         c = getca(fp);
  62. #endif
  63.     return c;
  64. }
  65.